<template>
  <div>
    <!-- 就诊人列表 -->
    <section class="sec_list">
      <scroller
        :onRefresh="refresh"
        :onInfinite="infinite"
      >
        <div v-for="(item,index) in list" :key="index" class="t_c_content">
          <div>
            <span @click="changePat(item.PATIENT_ID)">
              <!-- <i class="iconfont icon-dui" @click="changePat(item.PATIENT_ID, item)" :class="{ choosed: item.DEFAULTBZ=='y' }"> -->
              <svg style="" viewBox="0 0 1098 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
                fill="#ced4da" xmlns:xlink="http://www.w3.org/1999/xlink" width="20" height="20"
                :class="{ choosed: item.DEFAULTBZ=='y' }"
              ><defs><style type="text/css"></style></defs><path d="M476.808045 0.000043C213.401753 0.106685-0.031993 213.68973 0 477.074693S213.551052 953.98938 476.94668 954.021373s476.957344-213.412417 477.085315-476.808045A477.010665 477.010665 0 0 0 476.808045 0.000043z m273.761252 353.369671L441.861388 661.853674a43.1901 43.1901 0 0 1-62.023117 0L202.214984 484.251715a43.864079 43.864079 0 1 1 62.033781-62.033782l147.21959 147.21959 277.89897-276.86454a43.861946 43.861946 0 1 1 62.023117 62.033781z m0 0"></path></svg>
              <!-- </i> -->
            </span>
            <!-- <span @click="editPat(item, 'mod')"> -->
            <span @click="changePat(item.PATIENT_ID)">
              <span>{{item.PATIENT_NAME}}</span>
              <span>{{item.PATIENT_AGE}}&nbsp;&nbsp;{{item.PATIENT_SEX}}</span>
              <span>{{'病历号码：' + item.PATIENT_BLHM}}</span>
            </span>
            <span>
              <!-- <input type="button" value="删除" class="remove_button" @click="removePat(item.PATIENT_ID)"> -->
              <p @click="removePat(item.PATIENT_ID)">删除</p>
              <p @click="editPat(item, 'mod')">修改</p>
            </span>
          </div>
        </div>
      </scroller>
      <mt-button type="primary" size="large" class="addpat" @click="editPat('', 'add')">添加就诊人</mt-button>
    </section>
  </div>
</template>

<script>
export default {
  data() {
    return {

      list: [],

      patientKey: '',

      ts: this.newStore(),
      tq: this.getData(),
      page: 0,

      root: `https://${sessionStorage.getItem('hospitalDomainname')}/doctor`,

      fromPath: -1, // 来自那个路由或者路径返回层级
    };
  },
  created() {
    /* 标题 */
    document.title = '就诊人列表';
    this.fromPath = this.$route.query.fromPath;
    console.log(`--------------fromPath${this.fromPath}`);

    /* 初始化列表内容 */
    // this.getPatientList(1);
  },
  mounted() {
    if (sessionStorage.getItem('rybToken') == '' || sessionStorage.getItem('rybToken') == null) {
      this.$router.push('/login');
    }
  },
  components: {
  },
  methods: {
    refresh(done) {
      this.page = 0;
      this.getPatientList(1, done);
    },
    infinite(done) {
      setTimeout(() => {
        this.page += 1;
        this.getPatientList(this.page, done);
      }, 500);
    },
    getPatientList(page, fn) {
      const DATA = {
        rowsperpage: '10',
        page: `${this.page}`,
        keywords: `${this.patientKey}`,
      };
      this.tq.getPatientList(DATA).then((ts) => {
        if (ts.d.DATAOBJ.DATA.length < 1) {
          this.page = 0;
          fn(true);
          return;
        } else if (fn) {
          fn();
        }
        if (page == 1) {
          this.list = ts.d.DATAOBJ.DATA;
        } else {
          this.list = this.list.concat(ts.d.DATAOBJ.DATA);
        }
      });
    },
    /* 编辑就诊人信息 */
    editPat(PATIENTINFO, TYPE) { // TYPE: mod修改  add添加
      // console.log(`--------修改的就诊人信息：${JSON.stringify(PATIENTINFO)}`);
      this.$router.push({
        name: 'wode-editPatient',
        query: { PATIENTINFO: `${JSON.stringify(PATIENTINFO)}`, TYPE, fromPath: this.fromPath },
      });
      console.log('--------编程或者添加就诊人信息跳转---------');
    },
    // 删除病人
    removePat(id) {
      this.$messagebox.confirm('确定删除该就诊人?').then((action) => {
        if (action == 'confirm') { // 确认的回调
          const DATA = {
            patient_id: id,
          };
          this.tq.removePat(DATA).then((ts) => {
            if (ts.d.RESULT == '200') {
              this.page = 1;
              this.list = [];
              this.getPatientList(true);
              this.$messagebox('删除成功');
            } else {
              this.$messagebox(`删除失败: ${ts.d.RESULTTEXT}`);
            }
          });
        }
      }).catch((err) => {
        /*
        if (err == 'cancel') { // 取消的回调
          this.$messagebox('提示', '取消删除');
        }
        */
      });
    },
    // 修改默认病人
    changePat(id) {
      const DATA = {
        patient_id: id,
      };
      this.tq.changePat(DATA).then((ts) => {
        if (ts.d.RESULT == '200') {
          this.page = 1;
          this.list = [];
          this.getPatientList(true);
          this.$messagebox('更新成功');
        } else {
          this.$messagebox(`更新失败: ${ts.d.RESULTTEXT}`);
        }
        // this.$emit('reSetPat', patInfo);
      });
    },
  },
  watch: {
  },
  filters: {
  },
};
</script>
<style scoped lang="stylus">
.addpat
  position fixed
  bottom 0
  left 0
  right 0
  width 90%
  margin 1rem auto
.sec_list
  display flex
  flex-flow column || nowrap
  justify-content center
  border 0px solid blue
.t_c_content
  letter-spacing .05rem
  display flex
  flex-flow column || nowrap
  justify-content center
  border 0px solid #000
  border-radius 5px
  width 90%
  -webkit-box-shadow:0px 0px 4px #c8c8c8 ;
  -moz-box-shadow:0px 0px 4px #c8c8c8 ;
  box-shadow:0px 0px 4px #c8c8c8 ;
  margin .5rem auto
  background: #fff;
  div
    padding .5rem
    font-size 1rem
    display inline-flex
    flex-flow row || nowrap
    justify-content flex-start
    align-items center
    span
      display inline-flex
      flex-flow row || nowrap
      justify-content space-between
      margin-top .3rem
      margin-bottom .3rem
      &:nth-child(2)
        width 80%
        padding-left .5rem
        display flex
        flex-flow column || nowrap
        justify-content flex-start
        span
          font-size .8rem
          &:first-child
            font-weight bold
          &:nth-child(2)
            color #666
            padding 0
          &:last-child
            color #666
            letter-spacing 0rem
      &:last-child
        display inline-flex
        flex-flow column || nowrap
        justify-content flex-start
        align-content space-around /* | flex-end | center | space-between | space-around | stretch */
        p
          display inline-flex
          flex-flow column || nowrap
          justify-content flex-start
          align-items flex-start
          width 100%
          font-size .8rem
          color #dee2e6
          //margin 0rem
          font-weight normal
          line-height 2rem
/* 设置点样式 */
.choosed {
  fill: #1b6cbe;
}

</style>

